package org.prem.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class Main12 {

	public static void main(String args[]){
		StudentAddress12 studentAddress12_1 = new StudentAddress12();
		studentAddress12_1.setAddress_detail("Chennai, India");
		
		Student12 student12_1 = new Student12();
		student12_1.setStudent_name("Prem");
		student12_1.setStudentAddress12(studentAddress12_1);
		
		Student12 student12_2 = new Student12();
		student12_2.setStudent_name("Kumar");
		student12_2.setStudentAddress12(studentAddress12_1);
		
		studentAddress12_1.getStudents().add(student12_1);
		studentAddress12_1.getStudents().add(student12_2);
		
		StudentAddress12 studentAddress12_2 = new StudentAddress12();
		studentAddress12_2.setAddress_detail("Chicago, USA");
		
		Student12 student12_3 = new Student12();
		student12_3.setStudent_name("PremUS");
		student12_3.setStudentAddress12(studentAddress12_2);
		
		Student12 student12_4 = new Student12();
		student12_4.setStudent_name("KumarUS");
		student12_4.setStudentAddress12(studentAddress12_2);
		
		studentAddress12_2.getStudents().add(student12_3);
		studentAddress12_2.getStudents().add(student12_4);
		
		SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.save(studentAddress12_1);
		session.save(studentAddress12_2);
		session.getTransaction().commit();
		session.close();
		sessionFactory.close();
		
	}

}
